package org.dtrd.modules.achievement.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.util.Optional;

/**
 * @author 萧
 * @date:2021-09-01 1:54 下午
 **/
@Configuration
@Slf4j
public class AchievementConfig {

    @Value("${dtrd.achievement.judgement.normal}")
    private String normalNotice;
    @Value("${dtrd.achievement.judgement.good}")
    private String goodNotice;
    @Value("${dtrd.achievement.judgement.perfect}")
    private String perfectNotice;
    @Value("${dtrd.achievement.judgement.bad}")
    private String badNotice;
    @Value("${dtrd.achievement.judgement.none}")
    private String noneNotice;


    public enum AchievementState {

        NORMAL(1),

        GOOD(2),

        PERFECT(3),

        BAD(4),

        NONE(5);

        private int type;

        private AchievementState(int type) {
            this.type = type;
        }

        public int getType() {
            return type;
        }

        public void setType(int type) {
            this.type = type;
        }

        public static AchievementState valueOf(Integer type) {
            for (AchievementState value : values()) {
                if (value.type == type) {
                    return value;
                }
            }
            return null;
        }

    }

    public String getAchievementNotice(int type) {
        AchievementState state = AchievementState.valueOf(type);
        String notice = null;
        if (state != null) {
            switch (state) {
                case NORMAL:
                    notice = normalNotice;
                    break;
                case GOOD:
                    notice = goodNotice;
                    break;
                case PERFECT:
                    notice = perfectNotice;
                    break;
                case BAD:
                    notice = badNotice;
                    break;
                case NONE:
                    notice = noneNotice;
                    break;
            }
        } else {
            notice = normalNotice;
        }
        return notice;
    }

}
